/*
 * These files are distributed under the terms of the GNU GPLv2, the GNU General
 * Public version 2. See LICENSE.txt
 */
package fileCommodore.plugin.usermenu;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class EntryEditor extends JDialog 
{
	private EntryEditorPanel editor;
	private JButton ok = new JButton("Ok");
	private JButton cancel = new JButton("Cancel");
	private JPanel buttons = new JPanel(new BorderLayout());
	
	private boolean shouldSave = false;
	
	public EntryEditor(JDialog owner, Entry entry)
	{
		super(owner, "User Menu Entry Editor", true);
		
		editor = new EntryEditorPanel(entry);
		buttons.add(ok, BorderLayout.WEST);
		buttons.add(cancel, BorderLayout.EAST);
		
		setLayout(new BorderLayout());
		add(editor, BorderLayout.CENTER);
		add(buttons, BorderLayout.SOUTH);
		
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ok();
			}
		});
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cancel();
			}
		});
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				super.windowClosing(e);
				cancel();
			}
		});
		
		setLocationByPlatform(true);
		pack();
		setVisible(true);
	}
	
	private void ok()
	{
		shouldSave = true;
		editor.save();
		dispose();
	}
	
	private void cancel()
	{
		shouldSave = false;
		dispose();	
	}
	
	public boolean shouldSave()
	{
		return shouldSave;
	}
}
